﻿using QuickChat_Service.Repositories.Database;
using QuickChat_Service.Repositories.Repositories.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuickChat_Service.Repositories.Repositories.Fakes
{
    public class FakeChatRoomRepository : FakeRepository<ChatRoom>, IChatRoomRepository
    {
        public IQueryable<ChatRoom> GetChatRooms()
        {
            return GetAll();
        }

        public ChatRoom GetChatRoom(int chatRoomId)
        {
            return base.GetById(chatRoomId);
        }

        public void CreateNewChatRoom(int roomOwnersId)
        {
            base.Add(new ChatRoom(){
                RoomId = roomOwnersId
            });
        }

        public override void Update(ChatRoom entity, int targetId)
        {
            for (int i = 0; i < DbSet.Count(); i++)
            {
                if (DbSet.ElementAt(i).RoomId == entity.RoomId)
                {
                    DbSet[i] = entity;
                }
            }
        }

        public override void Delete(int id)
        {
            ChatRoom room = DbSet.SingleOrDefault(t => t.RoomId == id);

            base.Delete(room);
        }
    }
}